package com.lin.views;


import java.util.ArrayList;


import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.PinterestCircleBitmapDisplayer;
import com.yunfeng.supercall.R;
import com.yunfeng.supercall.activity.BaseActivity;
import com.yunfeng.supercall.bean.RecentCallsBean;
import com.yunfeng.supercall.bean.UserBean;


import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewForRecentCallOfOutil extends ListView{
	MyAdapter mFocusGameAdapter;
	Context mContext;
	DisplayImageOptions options;

	OnItemListViewEventListener mOnItemListViewEventListener;
	private UserBean mUser;
	public ListViewForRecentCallOfOutil(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		mContext = context;
		options = new DisplayImageOptions.Builder()
		.displayer(new PinterestCircleBitmapDisplayer(context.getResources().getDimensionPixelOffset(R.dimen.corners_avatar)))
		.showImageOnFail(R.drawable.default_avatar)
		.showImageOnLoading(R.drawable.default_avatar)
		.cacheInMemory(true)
		.cacheOnDisk(true)
		.considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565)
		.build();
		mUser = BaseActivity.getUser(context);
	}

	public void setOnItemListViewEventListener(OnItemListViewEventListener mOnItemListViewEventListener) {
		this.mOnItemListViewEventListener = mOnItemListViewEventListener;
	}

	public interface OnItemListViewEventListener {
		public void onItemAvatarLisener(RecentCallsBean maListInfo, int x, int y);
		public void onItemClickListener(RecentCallsBean maListInfo, int x, int y);
		public void onItemUserDetailListener(RecentCallsBean maListInfo, int x, int y);
		public void onItemLongCListener(RecentCallsBean maListInfo, int x, int y);
	}


	public void setDataList(ArrayList<RecentCallsBean> mFocusGameList) {
		if (mFocusGameAdapter == null) {
			mFocusGameAdapter = new MyAdapter(getContext(), mFocusGameList);
			setAdapter(mFocusGameAdapter);
		} else {
			mFocusGameAdapter.setmFocusGameList(mFocusGameList);
			mFocusGameAdapter.notifyDataSetChanged();
		}
	}

	private class MyAdapter extends BaseAdapter {

		LayoutInflater mLayoutInflater;
		ArrayList<RecentCallsBean> mDataList;
		int mSize;




		public MyAdapter(Context context,
				ArrayList<RecentCallsBean> mDataList) {
			// TODO Auto-generated constructor stub
			this.mDataList = mDataList;
			mLayoutInflater =  LayoutInflater.from(mContext);
		}

		public ArrayList<RecentCallsBean> getDataList() {
			return mDataList;
		}

		public void setmFocusGameList(ArrayList<RecentCallsBean> mFocusGameList) {
			this.mDataList = mFocusGameList;
		}


		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 3;
		}


		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public RecentCallsBean getItem(int position) {
			// TODO Auto-generated method stub
			return mDataList.get(position);
		}

		@Override
		public View getView(int position, View convertView, ViewGroup arg2) {
			// TODO Auto-generated method stub
			ViewHolder viewholder = null;

			int type = getItemViewType(position);
			if (convertView == null) {
				viewholder = new ViewHolder();
				convertView = mLayoutInflater.inflate(
						R.layout.list_item_recent_call_outils, null);
				viewholder.iv = (ImageView) convertView.findViewById(R.id.iv);
				viewholder.tv = (TextView) convertView.findViewById(R.id.tv);
				convertView.setTag(viewholder);

			} else {
				viewholder = (ViewHolder) convertView.getTag();
			}
			if(position == 0) {
				ImageLoader.getInstance().displayImage("drawable://" + R.drawable.ic_new_contact, viewholder.iv, options);
				viewholder.tv.setText("新建联系人");
			} else if(position == 1) {
				ImageLoader.getInstance().displayImage("drawable://" + R.drawable.ic_add_to_contact, viewholder.iv, options);
				viewholder.tv.setText("添加到联系人");
			} else if(position == 2) {
				ImageLoader.getInstance().displayImage("drawable://" + R.drawable.ic_send_msn2, viewholder.iv, options);
				viewholder.tv.setText("发短信");
			}
			

			return convertView;

		}



		void setLevelColor(int level,TextView tv, TextView tvLevel) {
			try {

				if(level == 0) {
					tvLevel.setTextColor(getResources().getColor(R.color.textview_title_listview));
					tv.setTextColor(getResources().getColor(R.color.textview_title_listview));	
				} else if(level == 1) {
					tvLevel.setTextColor(getResources().getColor(R.color.level_or));
					tv.setTextColor(getResources().getColor(R.color.level_or));
				} else {
					tvLevel.setTextColor(getResources().getColor(R.color.level_red));
					tv.setTextColor(getResources().getColor(R.color.level_red));
				}
			} catch(NullPointerException e) {

			}
		}

	}



	static class ViewHolder {
		ImageView iv;
		TextView tv;
		TextView tvNumber;
		ImageView ivIcon;
		TextView tvCallNum;
		TextView tvTime;
		ImageView isSuper;
		LinearLayout linearLayout;
		FrameLayout frameLayoutPersonalCard;
	}
}